﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using MemberMgr.Data.BusinessObjects;
using Ext.Net;
using Ext.Net.Utilities;

namespace MemberMgr.Website.Common
{
    public class PageBase : System.Web.UI.Page
    {
        private tUser userInfo;

        public tUser UserInfo { get { userInfo = Session[CommonConst.SESSION_USERINFO] as tUser; return userInfo; } }

        protected virtual void Page_Init(object sender, EventArgs e)
        {
            tUser userInfo = Session[CommonConst.SESSION_USERINFO] as tUser;

            //Login Check
            if (userInfo == null)
            {
                this.Session.Abandon();
                this.Response.Redirect("~/Login.aspx");
            }

            if (!this.IsPostBack)
            {
                this.Error += new EventHandler(PageBase_Error);
            }

        }

        void PageBase_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();
            Common.CommonUtil.logger.Error(ex.Message, ex);

            Ext.Net.MessageBox errMsg = new MessageBox();

            errMsg.Show(new MessageBoxConfig()
            {
                Icon = MessageBox.Icon.ERROR,
                Message = ex.Message,
                Title = "系统错误(MemberMgr)",
                Buttons = MessageBox.Button.OK
            });

            Server.ClearError();
        }


    }
}
